package com.foreknow.elmboot.mapper;

import com.foreknow.elmboot.po.Cart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CartMapper {
    /**
     * 查询购物车中商品信息
     * @param businessId
     * @return
     */
    public List<Cart> getCart(Integer businessId,String userId);

    /**
     * 购物车中没有商品时添加进购物车
     * @param cartId
     * @return
     */
    @Insert("insert into cart(foodId,businessId,userId,quantity) values(#{foodId},#{businessId},#{userId},1)")
    public int insertCart(Integer cartId,Integer userId,Integer foodId,Integer businessId);


    /**
     * 当购物车中有商品时的加一方法
     * @param quantity
     * @param userId
     * @param foodId
     * @param businessId
     * @return
     */
    @Update("update cart set quantity=#{quantity} where userId=#{userId} and businessId=#{businessId} and foodId=#{foodId}")
    public int updateCart(Integer quantity,Integer userId,Integer foodId,Integer businessId);

    /**
     * 当quantity为0时的删除方法
     * @param cart
     * @return
     */
    public int deleteCart(Cart cart);
}
